package cn.lili.common.security.enums;

import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;

/**
 * 场景
 *
 * @author liushuai(liushuai711 @ gmail.com)
 * @version v4.0
 * @Description:
 * @since 2022/8/23 19:31
 */
public enum SceneEnums {
    /**
     * 场景枚举，1.0版本与用户类型枚举保持同步
     */
    MEMBER("会员端"),

    STORE("商家端"),

    SUPPLIER("供应商端"),

    MANAGER("平台"),

    SEAT("坐席"),

    SYSTEM("系统"),
    URBAN_SUBSTATION("城市分站"),

    OPERATION_CENTER("运营中心"),

    LOWER("直推"),

    LOWERSUB("间推"),

    CASTELLAN("城主"),
    UNION("工会"),
    URBAN_SUBSTATION_ADDRESS("城市分站，省区"),
    DISTRIBUTION("分销员"),
    SHARE_BIND("分享绑定"),
    ;
    private final String description;

    SceneEnums(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    public String value() {
        return this.name();
    }

    public static SceneEnums defaultValue() {
        return MEMBER;
    }

    /**
     * 获取场景
     *
     * @param scene
     * @return
     */
    public static SceneEnums getScene(String scene) {
        try {
            return SceneEnums.valueOf(scene);
        } catch (IllegalArgumentException e) {
            throw new ServiceException(ResultCode.SCENE_NOT_SUPPORT);
        }
    }

    /**
     * 判断是否可以注册
     *
     * @param SceneEnums 注册场景枚举
     */
    public static void canRegister(SceneEnums SceneEnums) {
        if (SceneEnums.equals(SYSTEM) || SceneEnums.equals(MANAGER)) {
            throw new ServiceException(ResultCode.USER_AUTHORITY_ERROR);
        }
    }
}
